<template>
	<view>
		<view class="filter_box flex align-center justify-between pad0-40 box-sizing">
			<view class="fileter_item flex align-center font26 color66" v-for="(item,index) in list" :key="index"
				@click="changFilter(index)">
				<span>{{item.name}}</span>
				<block v-if="item.type==1">
					<image v-show="filterIndex!=index" src="@/static/jing-orderby/filter_tri.png" mode="widthFix">
					</image>
					<image v-show="filterIndex==index" :class="filterIndex==index&&item.isAsc?'rotateImg':''"
						src="@/static/jing-orderby/filter_tri_act.png" mode="widthFix"></image>
				</block>
				<block v-if="item.type==2">
					<image v-show="filterIndex!=index" src="@/static/jing-orderby/sx.png" style="width: 40rpx;"
						mode="widthFix"></image>
					<image v-show="filterIndex==index" src="@/static/jing-orderby/sx1.png" style="width: 40rpx;"
						mode="widthFix"></image>
				</block>
			</view>
		</view>
		<view v-show="show"  mode="top"
			style="position: absolute;background-color: #FFFFFF;width: 100%;">
			<view style="padding: 20rpx;">
				<view style="line-height: 80rpx;">价格区间(元)：</view>
				<view class="u-flex u-row-left">
					<view style="width: 200rpx;">
						<u--input  border="surround" placeholder="最低价" v-model="minPrice" type="number"  inputAlign="center"></u--input>
					</view>
					<view style="margin: 0 10rpx;"> ~ </view>
					<view style="width: 200rpx;">
						<u--input  border="surround" placeholder="最高价" v-model="maxPrice" type="number" inputAlign="center" ></u--input>
					</view>
				</view>
			</view>
			<view style="margin-top: 30rpx;" class="u-flex u-row-left">
				<view style="width: 50%;"><u-button type="warning" @tap="reset()" >重置</u-button></view>
				<view style="width: 50%;"><u-button type="primary" @tap="sub()" >确定</u-button></view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "orderby",
		props: {
			optionlist: {
				type: Array,
				default () {
					return []
				}
			}
		},
		data() {
			return {
				list: [],
				filterIndex: 0,
				show: false,
				minPrice:'',
				maxPrice:''
			};
		},
		created() {
			this.list = this.optionlist
		},
		methods: {
			sub(){
				this.$emit('change', {minPrice:this.minPrice,maxPrice:this.maxPrice,type:2})
				this.show=false
			},
			reset(){
				this.minPrice = ''
				this.maxPrice = ''
				this.sub()
			},
			close() {
				this.show = false
			},
			changFilter(index) {
				if (this.list[index].type == 2) {
					this.show = !this.show					
				}
				if (this.filterIndex == index) {
					this.list[index].isAsc = !this.list[index].isAsc
				} else {
					this.filterIndex = index
				}
				this.$forceUpdate()
				if (this.list[index].type != 2) {
					this.$emit('change', this.list[this.filterIndex])
				}
				
				// console.log(this.list);
			},
		}
	}
</script>

<style lang="scss">
	@import './jing-orderby.scss';

	.image-1 {
		width: 60rpx;
		height: 60rpx;
	}
</style>
